package com.kyivmohyla.kma2.client.utils;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.media.client.Audio;
import com.google.gwt.user.client.ui.*;

public class DialogBoxWithMessage {          //TODO Навіщо робити цей класс сінглтоном ?
    private static DialogBoxWithMessage instance = new DialogBoxWithMessage();
    private static Audio openSound = Audio.createIfSupported();

    public static DialogBoxWithMessage getInstance() {
        if (instance == null) {
            instance = new DialogBoxWithMessage();
        }
        return instance;
    }

    public void createDialogBoxWithMessage(String dialogBoxTitle, String message) {
        final DialogBox dialogBox = new DialogBox();
        dialogBox.addStyleName("gwt-DialogBox");
        dialogBox.getElement().getStyle().setZIndex(1000000);
        dialogBox.setText(dialogBoxTitle);
        VerticalPanel dialogContents = new VerticalPanel();
        dialogContents.addStyleName("dialogContents");
        dialogContents.setSpacing(4);
        HTML details = new HTML(message);
        dialogContents.add(details);
        dialogContents.setCellHorizontalAlignment(details, HasHorizontalAlignment.ALIGN_CENTER);
        Button closeButton = new Button("OK", new ClickHandler() {
            public void onClick(ClickEvent event) {
                dialogBox.hide();
            }
        });
        closeButton.setFocus(true);
        dialogContents.add(closeButton);
        dialogContents.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_RIGHT);
        dialogBox.setWidget(dialogContents);
        dialogBox.setAnimationEnabled(true);
        dialogBox.center();

        openSound.setSrc("sounds/Windows Notify System Generic.wav");
        openSound.play();

        dialogBox.show();
    }
}
